package com.yunchao.feature.lock.presentation.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.yunchao.feature.base.R
import com.yunchao.feature.lock.databinding.AdapterLockLogBinding
import com.yunchao.feature.lock.domain.model.LockLogModel
import kotlin.apply

internal class LockLogAdapter : BaseQuickAdapter<LockLogModel, LockLogAdapter.VH>() {

    internal class VH(
        parent: ViewGroup,
        val binding: AdapterLockLogBinding = AdapterLockLogBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        )
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onBindViewHolder(holder: VH, position: Int, item: LockLogModel?) {

        holder.binding.apply {
            lockTraceTitle.text = item?.lockLogTitle
            lockTraceNum.text = context.getString(R.string.张数STR, item?.pageNumber)
            lockTraceCoupon.text = context.getString(R.string.券别STR, item?.voucherTypeName)
            lockTraceOperator.text = context.getString(
                R.string.操作人STR,
                item?.lockOperator
            )
            lockTraceAuth.text = context.getString(R.string.授权人STR, item?.lockAuth)
            lockTraceDeviceId.text = context.getString(R.string.手持机IDSTR, item?.deviceId)
            lockTraceResult.text = context.getString(
                R.string.操作结果STR,
                item?.operatorResult
            )
            lockTraceTime.text = context.getString(R.string.操作时间STR, item?.operatorTime)
            if (item?.isLogistics == true) {
                lockTraceNum.visibility = View.GONE
                lockTraceDeviceId.visibility = View.GONE
                lockTraceCoupon.visibility = View.GONE
                lockTraceResult.visibility = View.GONE
            } else {
                lockTraceNum.visibility = View.VISIBLE
                lockTraceDeviceId.visibility = View.VISIBLE
                lockTraceCoupon.visibility = View.VISIBLE
                lockTraceResult.visibility = View.VISIBLE
            }
        }
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        return VH(parent)
    }
}